//
//  main.m
//  TP1-Partie-II
//
//  Created by Vincent Seguin on 12-01-23.
//  Copyright 2012 ETS. All rights reserved.
//

#import <Foundation/Foundation.h>

int AfficheInfoPath(void);
int AfficheInfoProcessus(void);
int AfficheInfoSignets(void);

int main (int argc, const char * argv[])
{

    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

    AfficheInfoPath(); 		// Fonctionnalité 1
    NSLog(@"\n");
    AfficheInfoProcessus(); 	// Fonctionnalité 2
    NSLog(@"\n");
    AfficheInfoSignets(); 		// Fonctionnalité 3
		
    AfficheInfoIntrospection(); 	// Fonctionnalité 4

    [pool drain];
     return 0;
}

int AfficheInfoPath () 
{
    NSString *path = [@"~" stringByExpandingTildeInPath];
    NSArray *pathComponents = [path pathComponents];
    
    
    for (NSString *pathComponent in pathComponents)
    {
        NSLog(@"%@", pathComponent);
    }
    
    return 0;
}

int AfficheInfoProcessus ()
{
	NSString *processName = [[NSProcessInfo processInfo] processName];
	int processIdentifier  = [[NSProcessInfo processInfo] processIdentifier];
	
	NSLog(@"Nom du processus courant: '%@' Process ID: '%d'", processName, processIdentifier);
	
	return 0;
}

int AfficheInfoSignets ()
{
	NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
	
	[dict setObject:[NSURL URLWithString: @"http://www.etsmtl.ca"] forKey:@"École de technologie supérieure"];
	[dict setObject:[NSURL URLWithString: @"http://www.polymtl.ca"] forKey:@"École polytechnique de Montréal"];
	[dict setObject:[NSURL URLWithString: @"http://cours.logti.etsmtl.ca/log350/"] forKey:@"LOG350"];
	[dict setObject:[NSURL URLWithString: @"http://ville.montreal.qc.ca"] forKey:@"Ville de Montréal"];
	[dict setObject:[NSURL URLWithString: @"http://www.montrealenlumiere.com/"] forKey:@"Montréal en lumières"];
	[dict setObject:[NSURL URLWithString: @"http://www.petiteecole.com/"] forKey:@"La petite école"];	
	
	for (id theKey in dict) {
		if ([theKey hasPrefix:@"École"] || 
			[theKey hasPrefix:@"école"] || 
			[theKey hasSuffix:@"École"] || 
			[theKey hasSuffix:@"école"])
		{
			id anObject = [[dict objectForKey:theKey] retain];
			NSLog(@"Clef: '%@' URL: '%@'", theKey, anObject);
		}
	}
	
	return 0;
}

int AfficheInfoIntrospection()
{
	NSMutableArray *elements = [[NSMutableArray alloc] init];
	[elements addObject: [NSString stringWithFormat:@"String de test!"]];
	[elements addObject: [NSURL URLWithString:@"TestURL"]];
	[elements addObject: [[NSProcessInfo processInfo] processName]];
	[elements addObject: [NSDictionary dictionaryWithObjectsAndKeys:@"Vinny", @"Member1", @"vchief", @"Member2", @"pmcanany", @"Member3", nil]];
	[elements addObject: [NSMutableString string]];
	
	NSMutableString *string = [elements objectAtIndex:4];
	[string appendString:@"Appended string"];
	
	for (id element in elements)
    {
        BOOL isLowerCaseString = [element respondsToSelector:@selector(lowercaseString)];
		
		NSLog(@"Classe: %@", [element class]);
		NSLog(@"Est Membre de NSString: %@", [element isMemberOfClass:[NSString class]] ? @"OUI" : @"NON");
		NSLog(@"Une sorte de NSString: %@", [element isKindOfClass:[NSString class]] ? @"OUI" : @"NON");
		NSLog(@"Repond a lowercasestring: %@", isLowerCaseString ? @"OUI" : @"NON");
		if(isLowerCaseString)
		{
			NSLog(@"lowercaseString is: %@", [element lowercaseString]);		
		}
		NSLog(@"======================================");
    }
	
	
	
    return 0;
}
